package com.huohuzhihui.web.controller.merchant;

import com.huohuzhihui.common.annotation.Log;
import com.huohuzhihui.common.core.controller.BaseController;
import com.huohuzhihui.common.core.domain.AjaxResult;
import com.huohuzhihui.common.core.page.TableDataInfo;
import com.huohuzhihui.common.enums.BusinessType;
import com.huohuzhihui.common.utils.poi.ExcelUtil;
import com.huohuzhihui.merchant.domain.MerResourceGroup;
import com.huohuzhihui.merchant.service.IMerResourceGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商户资源分组Controller
 * 
 * @author huohuzhihui
 * @date 2021-04-01
 */
@RestController
@RequestMapping("/merchant/resourcegroup")
public class MerResourceGroupController extends BaseController
{
    @Autowired
    private IMerResourceGroupService merResourceGroupService;

    /**
     * 查询商户资源分组列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:resourcegroup:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerResourceGroup merResourceGroup)
    {
        startPage();
        List<MerResourceGroup> list = merResourceGroupService.selectMerResourceGroupList(merResourceGroup);
        return getDataTable(list);
    }

    /**
     * 导出商户资源分组列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:resourcegroup:export')")
    @Log(title = "商户资源分组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MerResourceGroup merResourceGroup)
    {
        List<MerResourceGroup> list = merResourceGroupService.selectMerResourceGroupList(merResourceGroup);
        ExcelUtil<MerResourceGroup> util = new ExcelUtil<MerResourceGroup>(MerResourceGroup.class);
        return util.exportExcel(list, "resourcegroup");
    }

    /**
     * 获取商户资源分组详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:resourcegroup:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(merResourceGroupService.selectMerResourceGroupById(id));
    }

    /**
     * 新增商户资源分组
     */
    @PreAuthorize("@ss.hasPermi('merchant:resourcegroup:add')")
    @Log(title = "商户资源分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerResourceGroup merResourceGroup)
    {
        return toAjax(merResourceGroupService.insertMerResourceGroup(merResourceGroup));
    }

    /**
     * 修改商户资源分组
     */
    @PreAuthorize("@ss.hasPermi('merchant:resourcegroup:edit')")
    @Log(title = "商户资源分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerResourceGroup merResourceGroup)
    {
        return toAjax(merResourceGroupService.updateMerResourceGroup(merResourceGroup));
    }

    /**
     * 删除商户资源分组
     */
    @PreAuthorize("@ss.hasPermi('merchant:resourcegroup:remove')")
    @Log(title = "商户资源分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(merResourceGroupService.deleteMerResourceGroupByIds(ids));
    }
}
